package structural.adapter.java;

import java.util.Iterator;

/**
 * 数组到集合的转换器
 */
public class ArrayIterator implements Iterator<Object> {

    Object[] array;
    int pointer = -1;

    public ArrayIterator(Object[] array) {
        this.array = array;
    }

    @Override
    public boolean hasNext() {
        return array.length > (pointer + 1);
    }

    @Override
    public Object next() {
        pointer ++;
        return array[pointer];
    }

    @Override
    public void remove() {
        for (int i = pointer; i < array.length - 1 ; i++) {
            array[i] = array[i+1];
        }
        array[array.length - 1] = null;
    }

}
